<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="UTF-8">
    <title>视频观看记录</title>
    <style>
        body {
            font-family: "Microsoft YaHei", sans-serif;
            padding: 40px;
            background-color: #f8f9fa;
            color: #333;
        }

        h1 {
            font-size: 24px;
            border-left: 5px solid #4caf50;
            padding-left: 10px;
            margin-bottom: 20px;
        }

        .date-filter {
            margin: 10px 0;
            font-weight: bold;
        }

        .date-filter a {
            margin: 0 5px;
            text-decoration: none;
            color: #007bff;
        }

        .date-filter a:hover {
            text-decoration: underline;
        }

        .timeline-wrapper {
            position: relative;
            height: 100px;
            border: 1px solid #ddd;
            border-radius: 8px;
            background: #fff;
            margin: 20px 0;
            overflow: hidden;
        }

        .segment {
            position: absolute;
            top: 0;
            height: 100%;
        }

        .watching {
            background-color: #4caf50;
        }

        .no-eye {
            background-color: #ff9800;
        }

        .paused {
            background-color: #ccc;
        }

        .hour-line {
            position: absolute;
            top: 0;
            bottom: 0;
            width: 1px;
            background-color: #e0e0e0;
        }

        .hour-labels {
            display: flex;
            justify-content: space-between;
            font-size: 12px;
            margin-top: 5px;
        }

        .video-list {
            margin-top: 30px;
        }

        .video-item {
            margin-bottom: 10px;
            font-size: 15px;
        }
    </style>
</head>
<body>

    <h1>视频观看记录</h1>

    <div class="date-filter">
        日期选择：
        {% for d in dates %}
            {% if d == date %}
                <strong>{{ d }}</strong>
            {% else %}
                <a href="/traces?date={{ d }}">{{ d }}</a>
            {% endif %}
        {% endfor %}
    </div>

    <!-- 横向时间轴 -->
    <div class="timeline-wrapper">
        {% for seg in timeline %}
            <div class="segment {{ seg.status }}"
                 style="left: {{ seg.left }}%; width: {{ seg.width }}%;"
                 title="{{ seg.start }} ~ {{ seg.end }} ({{ seg.label }})">
            </div>
        {% endfor %}
        {% for i in range(24) %}
            <div class="hour-line" style="left: {{ (i / 24.0) * 100 }}%;"></div>
        {% endfor %}
    </div>

    <div class="hour-labels">
        {% for i in range(0, 24, 3) %}
            <span>{{ "%02d:00"|format(i) }}</span>
        {% endfor %}
    </div>

    <!-- 视频播放记录文字列表 -->
    <div class="video-list">
        {% for r in reports %}
            <div class="video-item">
                {{ r.start_time.strftime('%H:%M') }} - {{ r.end_time.strftime('%H:%M') }}：{{ r.name }}
            </div>
        {% else %}
            <p>当天无观看记录。</p>
        {% endfor %}
    </div>

</body>
</html>
